<template>
  <div class="myPage">
    <div style=" border-radius: 5px 5px 5px 5px;
  border: 1px solid #D7D7D7;">

    
    <search-form ref="search" :keys="workKey" @sub="search"  :showEd="!('see'===this.$route.query.state)" @termCode="termCode"></search-form>
    <hr style="height: 1px;border: 0;background: #eee;margin-bottom: 10px"/>
<!--    <div>{{tableData}}</div>-->
    <!-- <search-form ref="search" @delTag="delBat" :keys="workKey" @add="add" @planTag="planTag"></search-form> -->
    <div style="width: 100%;">
      <el-table
          :data="tableData"
          height="310"
          v-loading='tableLoading'
          ref="table"
          row-key="id"
          :disabled="!('see'===this.$route.query.state)"
          @selection-change="handleSelectionchangeS"
          style="width: 100%;overflow: auto;flex: auto;">
        <el-table-column
            :row-key="getRowKeys"
            :reserve-selection="true"
            type="selection"
            :selectable="diaSel"
            width="55">
        </el-table-column>
        <el-table-column
            prop="date"
            label="序号"
            width="50">
          <template slot-scope="scope">
            <span>{{scope.$index+1}}</span>
          </template>
        </el-table-column>
        <el-table-column
            prop="planBulkGoods.customerName"
            label="客户名称"
            width="160">
        </el-table-column>
        <el-table-column
            prop="planBulkGoods.billno"
            label="提单号"
            width="120">
        </el-table-column>
        <!-- <el-table-column
            prop="planBulkGoods.gname"
            label="货物名称"
            width="120">
        </el-table-column> -->
        <el-table-column
            label="委托数量"
            width="160" v-if="out">
          <template slot-scope="scope">
            <el-input-number :key="scope.$index + '-1'" size="small" controls-position="right" @input="changeS(scope.row)" v-model="tableData[scope.$index].
              planBulkGoods.planContainerGoods.gcentpks" :step="1" step-strictly :min="0" :max="tableData[scope.$index].
                planBulkGoods.gtpks"></el-input-number>
          </template>
        </el-table-column>

        <el-table-column
            label="委托重量（吨）"
            width="160" v-if="out">
          <template slot-scope="scope">
            <el-input-number size="small" :key="scope.$index + '-2'" controls-position="right" @input="changeS(scope.row)" v-model="tableData[scope.$index].
                planBulkGoods.planContainerGoods.gcentwg" :min="0" :max="tableData[scope.$index].
                planBulkGoods.gtwg" :step="0.01" step-strictly></el-input-number>
          </template>
        </el-table-column>
        <el-table-column
            v-if="'2' === active"
            prop="planBulkGoods.planContainerGoods.gcentpks"
            label="委托数量"
            width="120">
        </el-table-column>
        <el-table-column
            prop="planBulkGoods.planContainerGoods.gcentwg"
            label="委托重量（吨）"
            width="120" v-if="!out">
        </el-table-column>
        <el-table-column
            prop="planBulkGoods.gtpks"
            label="库存数量"
            width="120">
        </el-table-column>
        <el-table-column
            prop="planBulkGoods.gtwg"
            label="库存重量（吨）"
            width="120">
        </el-table-column>
        <el-table-column
            prop="planBulkGoods.gname"
            label="货名"
            width="120">
        </el-table-column>
        <el-table-column
            prop="planBulkGoods.busDelegateNo"
            label="业务委托号"
            width="150">
        </el-table-column>
        <el-table-column
            prop="planBulkGoods.operateDelegateNo"
            label="进提委托号"
            width="160">
        </el-table-column>
        
        <el-table-column
            prop="planBulkGoods.gname"
            label="货物名称"
            width="120">
        </el-table-column>
        
        <!-- <el-table-column
            prop="planBulkGoods.operateDelegateNo"
            label="进提委托号"
            width="160">
        </el-table-column> -->
        
        <el-table-column
            prop="planBulkGoods.morphologyName"
            label="货物形态"
            width="120">
        </el-table-column>
        
        <el-table-column
            prop="planBulkGoods.gtypeName"
            label="货种名称"
            width="120">
        </el-table-column>

  <!--      <el-table-column
            v-if="'1' === active"
            prop="planBulkGoods.spec1"
            label="规格型号1"
            width="120">
        </el-table-column>-->
        <el-table-column
            v-if="'2' === active"
            prop="planBulkGoods.markerno"
            label="唛头"
            width="120">
        </el-table-column>
        <el-table-column
            v-if="'2' === active"
            prop="planBulkGoods.gunit"
            label="计量单位"
            width="120">
        </el-table-column>

        <el-table-column
            prop="planBulkGoods.goodsFrom"
            label="货物来源"
            width="120">
        </el-table-column>
        <el-table-column
            prop="planBulkGoods.goodsTo"
            label="货物流向"
            width="120">
        </el-table-column>
        <el-table-column
            prop="planBulkGoods.remark"
            label="备注"
            width="120">
        </el-table-column>
        <el-table-column
            prop="planBulkGoods.spec1"
            label="规格型号"
            width="120">
        </el-table-column>
        <!-- <el-table-column
            prop="planBulkGoods.spec2"
            label="规格型号2"
            width="120">
        </el-table-column>
        <el-table-column
            prop="planBulkGoods.spec3"
            label="规格型号3"
            width="120">
        </el-table-column> -->
        <el-table-column
            prop="planBulkGoods.origin"
            label="产地"
            width="120">
        </el-table-column>
      </el-table>
    </div>
  </div>
    <el-dialog
        :title="title"
        :before-close="cancelForm"
        :visible.sync="dialog"
        custom-class="demo-drawer"
        ref="drawer">
      <div class="demo-drawer__content" style="display: flex;flex-wrap: wrap;
      flex-direction: column;align-content: space-around">
        <form-list :showEd="!see" @cal="dialog=false" @sub="submit" ref="formList" :keys="keys"></form-list>
      </div>
    </el-dialog>

    <div class='card'>
      <div class="blue"  margin-buttom='20px'>生成计划</div>
      <form-list-3  :planTag="tag1" :keys="keys1" @add="add" ref="formList3"  :showEd="'see'!==$route.query.state"></form-list-3>
    </div>
    <div style="display: flex;justify-content: center;">
      <el-button :loading="loading" @click="submitDate" type="primary" style="margin-top:20px;background: #0F47B8;" v-if="'see'!==$route.query.state">提交申请</el-button>
    </div>
    <newLeftMenu2 ref="newLeftMenu2" v-show="false"></newLeftMenu2>
  </div>
</template>

<script>
import searchForm from "./searchForm";
import formList from "@/views/businessProcessing/goodContent/moudel/formList";
import formList3 from "@/views/businessProcessing/goodContent/moudel/formList3";

export default {
  name: "bulkCargo",
  components:{
    searchForm,
    formList3,
    formList,
    newLeftMenu2
  },
  data() {
    return {
      tableLoading:false,
      keys1:['khlx','cblx','jsfs','kssj','lx','shf'],
      quSee:false,
      goodsType:[],
      ships:[],
      out:false,
      page:0,
      pageSize:10,
      workKey:[],
      keys:['form1'],
      active:'1',
      title:'新增',
      ZCCK_Gg:false,
      formLabelWidth:200,
      form:{},
      dialog:false,
      tableData: [],
      tableData1:[],
      tableData2:[],
      selection:[],
      tag:'',
      tag1:'',
      formList:{},
      see:false,
      myTable:[],
      loading:false,
    };
  },
  mounted() {
    this.getInfo()
    this.setTag()
    this.$refs.search.term()
    this.$refs.formList3.getVel()
  },
  watch:{
    '$route'(){
      //localStorage.setItem('myDate','')
    }
  },
 
  destroyed() {
    //localStorage.setItem('myDate','')
  },
   //通过路由规则，离开该组件时被调用
beforeRouteLeave (to, from, next) {
      console.log('About--beforeRouteLeave',to,from)
      let nowJsonData = JSON.stringify(this.$refs.search.form)
      let oldFormJson = JSON.stringify(this.$refs.search.oriForm)
      // let nowJsonData1 = JSON.stringify(this.$refs.addPlan.form)
      // let oldFormJson1 = JSON.stringify(this.$refs.addPlan.oriForm)
      // console.log('================================ ',nowJsonData,' 000000000000000000000000 ',oldFormJson) //;
      if(nowJsonData!=oldFormJson && this.quSee){
      // if(nowJsonData!=oldFormJson || nowJsonData1!=oldFormJson1){
      // if(this.tableData!= []){
        this.$nextTick(()=>{
          this.$confirm('存在未提交信息，确认关闭？',{
            closeOnHashChange:false,
            closeOnClickModal:false,
            distinguishCancelAndClose:true,
            closeOnPressEscape:false,
            confirmButtonText: '确定',
            cancelButtonText: '取消',
          })
                .then(_ => {
                  console.log('这边有问题',this.$route.path);
                  // console.log('这边有问题',this.$route.current);
                  this.$store.commit('setActiveMenuPath',next.fullPath)
                  // this.$router.push(to.fullPath)
                  next()
                })
                .catch(_ => {
                  console.log('是取消！！！！！！！！！！！！！！！！！',from.fullPath);
                  this.$store.commit('setActiveMenuPath',from.fullPath)
                  // this.$route.path = from.fullPath
                  // this.$router.push(from.fullPath)
                  // console.log('看看路由',this.$route.path)
                  this.$nextTick(()=>{
                    // this.$refs.newLeftMenu2.refresh = !this.$refs.newLeftMenu2.refresh
                    let path = {
                      index: from.fullPath,
                    }
                    // this.$refs.newLeftMenu2.getActivePath(path) 
                    this.$refs.newLeftMenu2.getPath(from.fullPath)
                    this.$refs.newLeftMenu2.linkTab(from.fullPath)
                  })
                  // this.$refs.newLeftMenu2.linkTab(from.fullPath)
                  // console.log('path: ' + from.fullPath,this.$route.path);
                });
        })
      }else{
        next()
      }
  },
  methods:{ 
    termCode(e){
      this.$refs.formList3.form.termCode=e
      this.$refs.formList3.getVel()
      console.log(e)
    },
    diaSel(){
      if(this.$route.query?.state  === 'see'){
        return false
      }else{
        return true
      }
    },
    search(){
      this.getGoods()
    },
    submitDate(){
      let that =this
      this.$refs.formList3.$refs.form.validate((valid) => {
          if (valid) {
            that.submitDate1()
            //alert('submit!');
            return true
          } else {
            this.$message.error('请填写必填项!')
            console.log('error submit!!');
            // this.loading=false
            return false;
          }
        });
    },
    submitDate1(){
        if(0===this.selection.length){
          this.$message.error('请选择数据！')
          this.loading=false
          this.dialog=false
          return
        }
        if(undefined===this.$refs.search.form.termCode){
          this.loading=false
          this.$message.error('请选择作业码头！')
          return;
        }
        // if(undefined===this.$refs.formList2.form.vslCd){
        //   this.$message.error('请选择船名航次！')
        //   return;
        // }
        let that=this
        let c= JSON.parse(JSON.stringify(this.$refs.formList3.form))
        c.planTag=this.tag
        //c.createUser='admin'
        // c.cstCstmcd=this.$refs.search.form.cstCstmcd
        // c.vslCd=this.$refs.search.form.vslCd
        // c.termCode=this.$refs.search.form.termCode//this.keys.includes('form1')?'HX':'LTG'
        c.opprc='ZYLX_CC'
        c=Object.assign(c,JSON.parse(JSON.stringify(this.$refs.search.form)))
        let k=JSON.parse(JSON.stringify(this.selection))
        let goods=[]
        k.forEach(item=>{
          goods.push(item.planBulkGoods)
        })
        this.$set(c,'planBulkGoods',goods)
        console.log(c)
        console.log('kkkk')
        console.log(this.tag)
        let type=that.tag
        console.log(c.id)
        if(null===c.id||undefined===c.id){
          type='_Add'
        }else{
          type='_Edit'
        }
        this.loading=true
        this.$api.shipE(c,this.tag+type).then(res=>{
          if(200===res.code){
            this.dialog=false
            let that= this
            this.$message.success({message:'_Add'===type?
                  '新增计划成功！':'编辑计划成功！',onClose(){
                that.selection=[]
                that.tableData=[]
                that.$refs.formList3.form={}
                localStorage.setItem('myDate','')
                that.link()
              }
            })
          }else{
            this.loading=false
            //this.$message.error(res.message)
          }
        }).catch(err=>{
          this.loading=false
          //this.$message.error(err.message)
        })
    },
    delBat(){
      let s = this.selection
      if(0===s.length){
        this.$message.error('请先选择货物！')
        return;
      }
      //console.log(s)
      //return
      //console.log(e.$index)
      let that=this

      this.$confirm('确定要删除货物吗？')
          .then(_ => {
            if('1' === that.active){
              that.tableData.forEach((item,index)=>{
                s.forEach(item1=>{
                  if(JSON.stringify(item1) === JSON.stringify(item)){
                    that.tableData.splice(index,1)
                    that.tableData=that.tableData1
                  }
                })
              })
            }
            if('2' === that.active){
              that.tableData2.forEach((item,index)=>{
                s.forEach(item1=>{
                  if(JSON.stringify(item1) === JSON.stringify(item)){
                    that.tableData2.splice(index,1)
                    that.tableData=that.tableData2
                  }
                })
              })
            }
            this.$refs.table.clearSelection()
            this.selection=[]
            this.$message.success('批量删除成功！')
          })
          .catch(_ => {});

    },
    changeS(e){
      /*console.log(9999999)
      console.log(e)*/
      this.$nextTick(() => {
        if(e.planBulkGoods.planContainerGoods.gcentwg>e.planBulkGoods.gtwg){
          e.planBulkGoods.planContainerGoods.gcentwg=e.planBulkGoods.gtwg
        }
        if(e.planBulkGoods.planContainerGoods.gcentpks>e.planBulkGoods.gtpks){
          e.planBulkGoods.planContainerGoods.gcentpks=e.planBulkGoods.gtpks
        }
        if(undefined!==e.planBulkGoods.planContainerGoods.gcentwg&&
            0!==e.planBulkGoods.planContainerGoods.gcentwg&&
            0!==e.planBulkGoods.planContainerGoods.gcentpks){
          //这里把数据重新赋值一下，不然就会出现bug，从第一页翻到第二页可以保留，在回到第一页选中的就没了
          this.$refs.table.toggleRowSelection(e, true);
          //this.$forceUpdate()
        }
        // else{
        //   this.$refs.table.toggleRowSelection(e, false);
        // }
      });
    },
    getGoods(){
      this.out = true
      this.tableData=[]
      console.log(this.$refs.search.form.termCode)
      if(undefined===this.$refs.search.form.termCode||''===this.$refs.search.form.termCode){
        this.$message.error('请选择码头！')
        return
      }
      let par={
        "planTag": this.tag,
        "termCode": this.$refs.search.form.termCode,
        "customerCode":JSON.parse(localStorage.getItem('userInfo')).customerCode,
      }

      if('jOutput'===this.$route.name){
        par.queryType='pickup'
      }else{
        par.queryType='out'
      }
      par=Object.assign(par,JSON.parse(JSON.stringify(this.$refs.search.form)))
      par.billno=Object.assign(par,JSON.parse(JSON.stringify(this.$refs.search.form))).billNo
      this.tableLoading = true
      this.$api.tosGetGoods(par).then(res=>{
        let tempData = []
        res.data.forEach(item=>{
          // let c={planBulkGoods:item}
          // c.planBulkGoods.planContainerGoods={}
          // c.planBulkGoods.planContainerGoods={
          //   gcentpks:0,//item.gtpks,
          //   gcentpksMax:item?.gtpks || 0,
          //   gcentwg:0,//item.gtwg
          //   gcentwgMax:item?.gtwg || 0
          // }
          // tempData.push(c)

            if(item.gtpks < 0){
              item.gtpks = 0
            }
            if(item.gtwg < 0){
              item.gtwg = 0
            }
          let temp = JSON.parse(JSON.stringify(item))
          let planContainerGoods={
            gcentpks:0,//item.gtpks,
            gcentpksMax:item.gtpks < 0  ? 0 : item.gtpks,
            gcentwg:0,//item.gtwg
            gcentwgMax:item.gtwg < 0 ? 0 : item.gtwg
          }
          Object.assign(temp,{planContainerGoods:planContainerGoods})
          let aaa = Object.assign({},{planBulkGoods:temp})
          tempData.push(aaa)
        })
        this.tableData2.forEach(item=>{
          this.myTable.push(item)
        })
        //this.myTable=Object.assign(this.myTable,this.tableData2)
        if(0!==this.myTable.length){
          tempData.forEach(item=>{
            this.myTable.forEach(item1=>{
              if(item.planBulkGoods.bulkGId===item1.planBulkGoods.bulkGId){
                //console.log(1111)
                item.planBulkGoods.planContainerGoods=item1.planBulkGoods.planContainerGoods
              }else{
                //console.log(22222)
              }
            })
          })
        }
        console.log(tempData,'-------------------0000000000----------------');
        // this.tableData = tempData.slice(84, 90)
        // this.tableData = tempData.slice(1, 83)
        this.tableData = tempData
        // this.$forceUpdate()
      }).catch((err)=>{
        console.error(err)
      }).finally(()=>{
        this.tableLoading = false
      })
    },
    async setTag(){
      let tag = null
      let url1=this.$route.query.type
      let url=this.$route.name
      //console.log(this.$route.query)
      this.tag=url1
      console.log(666)
      console.log(url)
      if(undefined===this.tag){
        if('jUnloadLift'===url){
          this.tag='XCZT_G'
          this.tag1='XCZT'
          this.keys1.push('cddw')
          this.keys1.push('hmh')
        }
        if('jUnloadIn'===url){
          this.tag='XCRK_G'
          this.tag1='XCRK'
          this.keys1.push('hmh')
        }
        if('jLoadLift'===url){
          this.tag='ZCZZ_G'
          this.tag1='ZCZZ'
          this.keys1.push('cddw')
          this.keys1.push('hmh')
        }
        if('jLoadIn'===url){
          this.tag='ZCCK_G'
          this.tag1='ZCCK'
          this.keys1.push('hmh')
        }
        if('jImport'===url){
          this.tag='JH_G'
          this.tag1='JH'
          this.keys1.push('cddw')
          this.keys1.push('hmh1')
        }
        if('jOutput'===url){
          this.tag='TH_G'
          this.tag1='TH'
          this.keys1.push('cddw')
          this.keys1.push('hmh1')
        }
      }
      this.$api.getGoodsType().then(res=>{
        this.goodsType=res.data
      }).catch()
      if('see'===(this.$route.query?.state || '')){
        this.quSee=false
      }else{
        this.quSee=true
      }
      
      //await this.getGoods()
      //''!==localStorage.getItem('myDate')
      if(undefined!==this.$route.query.id){
        let c=await this.$api.detailGoods({
          id:this.$route.query.id
        }).then(res=>{
          //console.log(res.data)
          return res.data
        }).catch(res=>{
          return null
        })
        // console.log('ppppppp')
        // console.log(c)
        let that=this
        this.$nextTick(() => {
          that.$refs.search.getPer()
          this.$refs.formList3.$refs.myUpload.file=JSON.parse(JSON.stringify(c.planAttachmentList))
          if(null!==c.termCode){
            this.$set(that.$refs.search.form,'termCode',c.termCode)
          }
          if(null!==c.vslCd){
            this.$set(that.$refs.search.form,'vslCd',c.vslCd)
          }
          that.$refs.formList3.getVel1()
          /*console.log(88888)
          console.log(c)
          console.log(that.$refs.search.form)*/
          //that.$forceUpdate()
        })

        c.planBulkGoods.forEach((item,index)=>{
          this.tableData.push({
            planBulkGoods:item,
            plansExt:c.plansExt,
            edit:1
          })
          //this.$refs.table.toggleRowSelection(this.tableData[index], true);
          /*this.$refs.table.toggleRowSelection(item, true);
          this.$forceUpdate()*/
        })

        try {
          this.$refs.formList3.form=c
          this.$refs.search.form.termCode=c.termCode
        }catch (e) {
          console.log(e)
        }
        if('ZCCK_G'===(this.$route.query?.type || '')||('TH_G'===this.$route.query?.type || '')) {
          this.myTable = JSON.parse(JSON.stringify(this.tableData))
          this.getGoods()
        }
        //console.log(c)
      }else if('ZCCK_G'===this.$route.query.type||('TH_G'===this.$route.query?.type || '')){
        this.getGoods()
      }
    },
    getInfo(){
      console.log(this.$route.query)
      this.quSee=this.$route.query?.state || ''
      if(undefined===this.$route.query.state){
        console.log(88888)
        localStorage.setItem('myDate','')
      }
      this.see = this.quSee || 'true' === this.quSee;
      this.workKey=['mt','tdh','zxc','tdh','jth']
      this.$api.getCustomerInfo().then(res=>{
        this.$set(this.$refs.formList3.form,'customerPhone',res.data.tel)
      }).catch
      // if('ZCCK_G'===this.$route.query.type||'TH_G'===this.$route.query.type){
      //   this.workKey=['work','shipName','comType','num','out','del','add','import']
      // }else{
      //   this.workKey=['work','shipName','comType','num','ship1','out','del','add','import']
      // }
    },
    submit(){
      if(this.keys.includes('form1')){
        //console.log(66555237496)
        console.log(this.$refs.formList.form)
        console.log(8888888)
        console.log(this.tableData1)
        console.log(this.tableData)
        let c=JSON.parse(JSON.stringify(this.$refs.formList.form))
        if('新增'===this.title&&1!==c.edit){
          this.tableData1.push(c)
        }
        this.tableData=this.tableData1
        //this.$refs.table.toggleRowSelection(c, true);
        this.dialog=false
      }
      if(this.keys.includes('form3')){
        //console.log(66555237496)
        console.log(this.$refs.formList.form)
        let c=JSON.parse(JSON.stringify(this.$refs.formList.form))
        if('新增'===this.title&&1!==c.edit){
          this.tableData2.push(c)
        }
        /*this.tableData2.push(c)*/
        this.tableData=this.tableData2
        this.dialog=false
      }
      if(this.keys.includes('form2')){
        /*console.log(this.selection.length)
        console.log(this.$refs.formList.form)*/
        let that=this
        let c= JSON.parse(JSON.stringify(this.$refs.formList.form))
        c.planTag=this.tag
        //c.createUser='admin'
        c.cstCstmcd=this.$refs.search.form.cstCstmcd
        c.vslCd=this.$refs.search.form.vslCd
        c.termCode=this.$refs.search.form.termCode//this.keys.includes('form1')?'HX':'LTG'
        c.opprc='ZYLX_CC'
        let k=JSON.parse(JSON.stringify(this.selection))
        let goods=[]
        k.forEach(item=>{
          goods.push(item.planBulkGoods)
        })
        this.$set(c,'planBulkGoods',goods)
        console.log(c)
        console.log('kkkk')
        console.log(this.tag)
        let type=that.tag
        console.log(c.id)
        if(null===c.id||undefined===c.id){
          type='_Add'
        }else{
          type='_Edit'
        }
        this.$api.shipE(c,this.tag+type).then(res=>{
          if(200===res.code){
            this.dialog=false
            let that= this
            this.$message.success({message:'_Add'===type?
                  '新增计划成功！':'编辑计划成功！',onClose(){
                that.link()
              }
            })
          }else{
            //this.$message.error(res.message)
          }
        }).catch(err=>{
          //this.$message.error(err.message)
        })
      }
      /*console.log(this.$refs.formList.form)
      this.$api.xAdd(this.$refs.formList.form).then().catch()*/
    },
    planTag(){
      if(0===this.selection.length){
        this.$message.error('请选择数据！')
        this.dialog=false
        return
      }
      if(undefined===this.$refs.search.form.termCode){
        this.$message.error('请选择作业码头！')
        return;
      }
      if(undefined===this.$refs.search.form.vslCd){
        this.$message.error('请选择港口！')
        return;
      }

      if(!this.quSee||'false'===this.quSee){
        this.see=false
      }else{
        this.see=true
      }
      this.keys=['form2']
      this.title='生成计划'
      this.dialog=true
      this.$nextTick(res=>{
        //this.$refs.formList.form.plansExt.createUser='admin'
        console.log(99999)
        /*let e=localStorage.getItem("userInfo");
        console.log(e)
        let b=this.$store;
        console.log(b)*/
        /*let e=localStorage.getItem("userInfo");
        if(null===e){
          this.$refs.formList.form.plansExt.createUser=''//'admin'
        }else{
          this.$refs.formList.form.plansExt.createUser=JSON.parse(e).name
        }*/
        if(undefined!==this.formList.id&&null!==this.formList.id){
          this.$refs.formList.form=this.formList
        }else{
          this.$refs.formList.form={
            plansExt:{
              createUser:'',
              recipient:'',
              billNo:'',
              moveTo:''
            },
            planBulkGoods:{
              receiverName:'',
              morphology:this.keys.includes('form1')?'HWXT_SZH':'HWXT_JZH',
              gtypecd:'',
              planContainerGoods:{},
              gname:'',
              gunit:'',
            },
            planContainerGoods:{
              gcentwg:'',
              gcentpks:''
            },
            isCheck:-1,
            billno:1
          }
        }
        this.$forceUpdate()
      })
    },
    add(){
      this.see=false
      if('1'===this.active){
        this.keys=['form1']
      }
      if('2'===this.active){
        this.keys=['form3']
      }
      console.log(888888888)
      console.log(this.keys)
      //this.keys=['form1']
      this.title='新增'
      this.dialog=true
      this.$nextTick(res=>{
        /*this.$refs.formList.form={
          default: () => []
        }*/
        this.$refs.formList.getGoods()
        this.$refs.formList.form={
          plansExt:{
            createUser:'',
            recipient:'',
            billNo:''
          },
          planBulkGoods:{
            receiverName:'',
            morphology:this.keys.includes('form1')?'HWXT_SZH':'HWXT_JZH',
            gtypecd:'',
            planContainerGoods:{},
            gname:'',
            gunit:'',
          },
          planContainerGoods:{
            gcentwg:'',
            gcentpks:''
          },
          isCheck:-1,
          billno:1
        }

      })
    },
    handleSelect(e){
      console.log(e)
      this.active=e
      console.log(e)
      if('1'===e){
        console.log(777)
        this.tableData=this.tableData1
        this.keys=['form1']
      }
      if('2'===e){
        console.log(888)
        this.tableData=this.tableData2
        this.keys=['form3']
      }
      //console.log(this.active)
    },
    link(){
      this.$router.push({
        query:{
          name:'jGoods'
        },
        name:'success'
      })
    },
    cancelForm() {
      //this.keys=['form1']
      this.ZCCK_Gg = false;
      this.dialog = false;
      /*this.$refs.formList.form={
        default: () => []
      }*/
      //clearTimeout(this.timer);
    },
    del(e){
      console.log(e.$index)
      let that=this
      this.$confirm('确定要删除货物吗？')
          .then(_ => {
            if('1' === that.active){
              that.tableData1.splice(e.$index,1)
              that.tableData=that.tableData1
            }
            if('2' === that.active){
              that.tableData2.splice(e.$index,1)
              that.tableData=that.tableData2
            }
            this.$refs.table.clearSelection()
            this.selection=[]
            this.$message.success('删除成功！')
          })
          .catch(_ => {});

    },
    handleClick(row,e) {
      if('1'===this.active){
        this.keys=['form1']
      }
      if('2'===this.active){
        this.keys=['form3']
      }
      //this.keys=['form1']
      console.log(row);
      row.edit=1
      //console.log('ppppppp')
      if('see'!==e){
        this.title='编辑'
        this.see=false
      }else{
        this.title='查看'
        this.see=true
      }
      this.dialog=true
      this.$nextTick(res=>{
        this.$refs.formList.getGoods()
        this.$refs.formList.form=row//JSON.parse(JSON.stringify(row))
      })
    },
    handleSelectionchangeS(val) {
      this.selection = val;
      //this.$refs.table.toggleRowSelection(val, true);
    },
    getRowKeys(row) {
      return row.id
    },
    getRowKeys11(row) {
      return (row?.planBulkGoods?.busDelegateNo || '--') + '_' + (row?.planBulkGoods?.bulkGId || '--') + '_' + (row?.planBulkGoods?.operateDelegateNo || '--') 
    },
  },
}
</script>

<style scoped lang="scss">
:deep .el-input.is-disabled .el-input__inner {
  color: #666

}
:deep .el-textarea.is-disabled .el-textarea__inner {
  color: #666
}
.el-menu-item {
  height: 39px;
  line-height: 39px;
}
.el-menu{
  border: none;
  background: transparent;
}
.el-menu::after{
  border: none;
  background: transparent;
}
.myPage{
  background: #fff;
  padding: 10px 20px 20px 20px;
  border-radius: 6px;
  //height: 660px;
  //overflow: auto;
}
.card{
  margin-top: 20px;
  border-radius: 5px 5px 5px 5px;
  opacity: 1;
  border: 1px solid #D7D7D7;
  .blue{
    border-left: 5px solid #0F47B8;
    margin: 20px 0 0 20px;
    padding-left: 10px;
    height: 23px;
  }
}
</style>
